# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Kaizhao Zhang <zhangkaizhao@gmail.com>

pkgname=pyright
pkgver=1.1.306
pkgrel=1
pkgdesc='Type checker for the Python language'
arch=('any')
url=https://github.com/microsoft/pyright
license=('MIT')
depends=('nodejs')
makedepends=('npm')
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz")
b2sums=('517a4520d07febecf0902a7cc66850e09afb0591793b580b5d04c87aec3c121fb760195fdb708ff671fdff017b62420dd7ea2f0213fabb7b0eee5061ffe1c667')

prepare() {
  cd $pkgname-$pkgver
  npm ci
}

build() {
  cd $pkgname-$pkgver/packages/$pkgname
  npm run build
}

package() {
  local _npmdir=/usr/lib/node_modules/$pkgname
  install -d "$pkgdir"/{usr/bin,$_npmdir,usr/share/doc/$pkgname}
  ln -s $_npmdir/index.js "$pkgdir"/usr/bin/$pkgname
  ln -s $_npmdir/langserver.index.js \
    "$pkgdir"/usr/bin/$pkgname-langserver

  cd $pkgname-$pkgver
  cp -r {CONTRIBUTING,README}.md docs "$pkgdir"/usr/share/doc/$pkgname
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname LICENSE.txt

  cd packages/$pkgname
  cp -r dist {,langserver.}index.js "$pkgdir"/$_npmdir
}
